package com.dytj.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dytj.pojo.User;
import com.dytj.service.UserServiceImpl;

@WebServlet("/addUserServlet")
public class AddUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	public UserServiceImpl userDao = new UserServiceImpl();
    public AddUserServlet() {
        super();
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = new User();
		String accounts = request.getParameter("accounts");
		String password = request.getParameter("password");
		boolean result = false;
		try {
			result = userDao.addUser(user);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		if(result) {
			//成功
	
			request.getRequestDispatcher("/WEB-INF/jsp/userLogin.jsp").forward(request,response);
		}else {
			//失败
			String info = "增加用户失败！";
			request.setAttribute("outputMessage", info);
			request.getRequestDispatcher("/WEB-INF/jsp/info.jsp").forward(request,response);
		}
	}

}
